package com.hddz.comlib.util;

import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;

import android.app.Activity;
import android.widget.Toast;

import com.hddz.comlib.service.BluetoothService1;

public class BluetoothPrintUtility {

	public static void printPage(Activity activity, BluetoothService1 mService, String mInfo) {
		DecimalFormat df = new DecimalFormat("0.0");
		if (mService != null) {
			// Check that we're actually connected before trying anything
			if (mService.getState() != BluetoothService1.STATE_CONNECTED) {
				Toast.makeText(activity, "未连接", Toast.LENGTH_SHORT).show();
				return;
			}

			// Check that there's actually something to send
			if (mInfo.length() > 0) {
				// Get the message bytes and tell the BluetoothService to write
				byte[] send;
				try {
					send = mInfo.getBytes("GB2312");
				} catch (UnsupportedEncodingException e) {
					send = mInfo.getBytes();
				}
				mService.write(send);
			}
		} else {
			Toast.makeText(activity, "打印设备未连接，请先扫描设备", Toast.LENGTH_SHORT).show();
		}
	}
}
